package com.vtquang.mymaps.adapter;

import java.util.ArrayList;

import com.vtquang.mymaps.R;
import com.vtquang.mymaps.place.PlacesChose;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class PlaceListAdapter extends BaseAdapter {

	private static ArrayList<PlacesChose> itemDetailsrrayList; 
	private LayoutInflater l_Inflater;

	public PlaceListAdapter(Context context, ArrayList<PlacesChose> results) {
		itemDetailsrrayList = results;
		l_Inflater = LayoutInflater.from(context);
	}

	public int getCount() {
		// TODO Auto-generated method stub
		return itemDetailsrrayList.size();
	}

	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return itemDetailsrrayList.get(arg0);
	}

	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	public View getView(int position, View convertView, ViewGroup arg2) {
		// TODO Auto-generated method stub

		ViewHolde holder;
		if (convertView == null) {
			convertView = l_Inflater.inflate(R.layout.places_row, null);
			holder = new ViewHolde();
			holder._name = (TextView) convertView.findViewById(R.id.tendiadiem);
			holder._picture = (ImageView) convertView
					.findViewById(R.id.anhdiadiem);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolde) convertView.getTag();
		}

		holder._name.setText(itemDetailsrrayList.get(position).getName());
		holder._picture.setImageResource(itemDetailsrrayList.get(position)
				.getPicture());

		return convertView;
	}

	private class ViewHolde {
		TextView _name;
		ImageView _picture;
	}
}
